/*
* 包含多个基于 state 的 getters 计算属性的对象
* */
export default {
  allTotalCount (state) {
    return state.cartGoods.length
  }, // 购物车商品的商品的个数
  goodsCountAndAmount (state) {
    let o = {
      count: 0, // 勾选的数量
      amount: 0 // 勾选的总价
    }
    state.cartGoods.forEach(item => {
      if (item.selected) {
        o.count += item.count
        o.amount += item.price * item.count
      }
    })
    return o
  }, // 购物车的勾选的数量及总价
  goodsCartIds (state) {
    // 获取 state 中所有的商品 id, 拼接一个用逗号分隔的 字符串
    let idArr = []
    state.cartGoods.forEach(item => idArr.push(item.id))
    return idArr
  }, // [id, ...]
  goodsCount (state) {
    let o = {}
    state.cartGoods.forEach(item => o[item.id] = item.count)
    return o
  }, // { id: count, ... }
  goodsSelected (state) {
    let o = {}
    state.cartGoods.forEach(item => o[item.id] = item.selected)
    return o
  } // { id: selected, ... }
}
